package zuoye01;

import java.util.Arrays;

public class SimpleArrayList<E> {
	private final static int DEFAULT_SIZE=10;
	private int size;
	private Object[] target;
	public SimpleArrayList() {
		this (DEFAULT_SIZE);
	}
	public SimpleArrayList(int size) {
		Object[] targer = new Object[size];
	}
	public void add(E e) {
		if (this.size<DEFAULT_SIZE) {
			target[size++]=e;
		}else {
			target=Arrays.copyOf(target, size*2);
			target[size++]=e;
		}
	}
	public E get(int index){
		return(E)target[index];
	}
	

	public int size(){
		return this.size;
	}
	public int indexOf(Object obj) {
		if (obj==null) {
			for (int i = 0; i < target.length; i++) {
				if (target[i]==null) {
					return i;
				}
			}
		}else {
			for (int i = 0; i < target.length; i++) {
				if (obj.equals(target[i])) {
					
				}
			}
		}
		return -1;
	}
	public E remove(int index) {
		E e=get(index);
		System.arraycopy(target, index+1, target, index,size-index-1);
		target[--size]=null;
		return e;
	}
	public boolean remove(Object o) {
		if (o==null) {
			for (int i = 0; i < target.length; i++) {
				if (target[i]==null) {
					remove(i);
					return true;
					
				}
				
			}
			
		}else {
			for (int i = 0; i < target.length; i++) {
				if (o.equals(target[i])) {
					remove(i);
					return true;
				}
			}
		}
		return false;
	}
	public void clear() {
		for (int i = 0; i < target.length; i++) {
			target[i]=null;
		}
		size=0;
	}
}

